package com.inlycat.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.inlycat.entity.Node;
import com.inlycat.mapper.NodeMapper;
import com.inlycat.service.NodeService;

/**
 * @author jarvan4dev@163.com
 * @since 2015年8月27日下午6:10:02
 * @category
 
  
 **/
@Service("nodeService")
public class NodeServiceImpl implements NodeService {

	@Resource
	private NodeMapper nodeMapper;

	@Override
	public List<Node> select(Node node) {
		/**
		 * 先将本次选择的节点的被选择次数更新
		 */
		nodeMapper.updateSelective(node);
		List<Node> nodes = nodeMapper.select(node);
		if (nodes != null) {
			int allCount = 0;
			for (int i = 0; i < nodes.size(); i++) {
				allCount += nodes.get(i).getCount();
			}
			for (int i = 0; i < nodes.size(); i++) {
				double percent = nodes.get(i).getCount()*1.0/allCount;
				nodes.get(i).setPercent(percent);
			}
		}
		return nodes;
	}

}
